﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Admin_Account_Modules_visa_List : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
       btnimgDel.Attributes.Add("onclick", "a=confirm('Đồng ý xóa?');document.getElementById('" + hidDelete.ClientID + "').value=a;");
       // this.btnDuyet.Attributes.Add("onclick", "a=confirm('Đồng ý duyệt?');document.getElementById('" + this.Duyet.ClientID + "').value=a");
        if (!this.IsPostBack) {
            LoadGrdView();
        }
    }
    private void LoadGrdView()
    {
        CMSDataContext db = new CMSDataContext();
        var query = from p in db.wVISAs
                    select p;
        this.grdDs.DataSource = query;
        this.grdDs.DataBind();
    }

    private void Delete() {
        
        int n = 0;
        n = this.grdDs.Rows.Count;
        if (this.hidDelete.Value == "true")
        {
            bool isselected = false;
            if (n > 0)
            {
                CheckBox chk;
                for (int i = 0; i < n; i++)
                {
                    chk = (CheckBox)this.grdDs.Rows[i].FindControl("chkDelete");
                    try
                    {
                        if (chk.Checked == true)
                        {
                            int _ID = Convert.ToInt32(this.grdDs.DataKeys[this.grdDs.Rows[i].RowIndex].Value);
                            CMSDataContext db = new CMSDataContext();
                            wVISA visa = db.wVISAs.Single(p => p.ID == _ID);
                            db.wVISAs.DeleteOnSubmit(visa);
                            db.SubmitChanges();
                            isselected = true;
                        }
                    }
                    catch
                    {

                    }
                }
                if (isselected)
                {
                    
                }
                else
                {
                  
                }
            }
        }
        else
        {
           
        }
        this.LoadGrdView();
    }
    protected void GRV_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.grdDs.PageIndex = e.NewPageIndex;
        this.LoadGrdView();
    }
    protected void btnimgDel_Click(object sender, ImageClickEventArgs e)
    {
        Delete();
    }
}